<!--  -->
<template>
    <div class="col-md-10">
    <form action="" method="post" role="form" @submit.prevent="addHero()">
      <legend>添加英雄</legend>
      <div class="form-group">
        <label>英雄名称</label>
        <input  v-model="heroName" type="text" class="form-control">
      </div>
      <div class="form-group">
        <label>英雄性别</label>
        <input v-model="gender" type="text" class="form-control">
      </div>
      <button type="submit" class="btn btn-primary">提交</button>
    </form>
  </div>
</template>

<script>
// import get from './hero'
// import axios from 'axios'
export default {
  data () {
    return {
        heroName:'',
        gender:''
    }
  },
  methods: {
       addHero(){
            if(this.heroName ==''|| this.gender==''){
                return alert('内容不能为空！！')
            }
            var data = {
            heroName:this.heroName,
            gender:this.gender,
            time:new Date()
            }
            this.$axios({
                method:"post",
                url:'heroes',
                data:data
            }).then(()=>{
               this.$router.push('/hero')
            //   this.getHero();
            // console.log(res.data);

            })
       } 
  },
}

</script>

<style lang='stylus' scoped>

</style>
